<template>
	<view class="equip-list-container">
		<view class="equip-list-tabs" v-if="!confirmCode || confirmCode == '0'">
			<uni-segmented-control class="top-nav-tabs-main" :current="tabIndex" :values="tabs" @clickItem="tabChange"></uni-segmented-control>
		</view>
		<equip-list-scroller
			v-if="confirmCode && confirmCode != '0'"
			ref="mescrollItem"
			:confirmCode="confirmCode"
			:maintainType="maintainType"
			:i="2"
			:index="2"
			:tabs="tabs"
			:top="0"
			:deletedTaskIds="deletedTaskIds"
			@refresh="()=>deletedTaskIds=[]"
		></equip-list-scroller>
		<swiper
			v-else
			:style="{ height: height }"
			:current="tabIndex"
			@change="
				e => {
					tabIndex = e.detail.current;
				}
			"
			:disable-touch="true"
		>
			<swiper-item v-for="(tab, i) in tabs" :key="i">
				<equip-list-scroller
					ref="mescrollItem"
					:confirmCode="confirmCode"
					:maintainType="maintainType"
					:i="i"
					:index="tabIndex"
					:tabs="tabs"
					:top="80"
					:deletedTaskIds="deletedTaskIds"
					@refresh="()=>deletedTaskIds=[]"
				></equip-list-scroller>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
import MescrollMixin from '@/components/mescroll-uni/mescroll-mixins.js';
import equipListScroller from './equip-list/equip-list-scroller.vue';
// import {apiNewList} from "@/api/mock.js"

export default {
	components: {
		equipListScroller
	},
	data() {
		return {
			deletedTaskIds:[],
			confirmCode: '',
			maintainType: '',
			height: '400px', // 需要固定swiper的高度
			tabs: ['未开始', '进行中', '已执行'],
			tabIndex: 0 // 当前tab的下标
		};
	},
	methods: {
		tabChange(e) {
			if (this.tabIndex !== e.currentIndex) this.tabIndex = e.currentIndex;
		},
		// 轮播菜单
		swiperChange(e) {
			this.tabIndex = e.detail.current;
		}
	},

	onShow() {
		// 返回刷新: https://www.mescroll.com/uni.html#note 第二点
		// if(this.canReset){
		// 	let curMescroll = this.getMescroll(this.tabIndex)
		// 	curMescroll && curMescroll.resetUpScroll()
		// }
		// this.canReset = true
	},
	onLoad: function(option) {
		//option为object类型，会序列化上个页面传递的参数
		this.confirmCode = option.confirmCode;
		this.maintainType = option.maintainType;
		this.maintainTypeName = ['点检', '保养', '维修'][parseInt(option.maintainType) - 1];

		this.confirmCodeName = ['列表', '确认', '质检'][parseInt(option.confirmCode || 0)];
		// this.tabs=['待'+this.maintainTypeName , this.maintainTypeName +'中', '已'+this.maintainTypeName ]
		// 需要固定swiper的高度
		// if(parseInt(option.confirmCode || 0)>0 ){
		// 	// 班长确认和质量确认 不需要tab

		// }

		this.height = uni.getSystemInfoSync().windowHeight + 'px';
		uni.setNavigationBarTitle({
			title: this.maintainTypeName + this.confirmCodeName
		});
		
		uni.$on('onEquipTaskDetailSave', (e)=>{
			this.deletedTaskIds.push(e.id)
			// this.$refs.mescrollItem.removeTask(e.id)
		})
	},
	onReady() {}
};
</script>

<style scoped>
.equip-list-container {
	background: #fff;
}
.equip-list-tabs {
	margin-top: 10rpx;
	background-color: #fff;
	position: fixed;
	width: 710rpx;
	margin-left: 20rpx;
	margin-bottom: 10rpx;
	z-index: 99;
}
</style>
